package com.ym.pms.utils;

/**
 * @Author: xybh
 * @Description:
 * @Date: Created in 17:16 2020/12/10
 * @Modified:
 */

import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;

import com.tencentcloudapi.captcha.v20190722.CaptchaClient;
import com.tencentcloudapi.captcha.v20190722.models.*;;

public class DescribeCaptchaResult {

    public static String check(String rand, String ticket, String userIp) {
        try {
            String secretKey = "QbQ2QFRpwVcuEJ5PmHWQOmOaamI1Ua6h";
            String secretId = "AKID08zYrJ6WCbkbBqrLKzO6tQiJABaIqBMI";
            String endPoint = "captcha.tencentcloudapi.com";
            Long captchaType = 9L;
            Long captchaAppId = 2032359745L;
            String appSecretKey = "023RfcLdw2T_bj0_ahZPUJg**";
            Credential cred = new Credential(secretId, secretKey);

            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint(endPoint);

            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);

            CaptchaClient client = new CaptchaClient(cred, "", clientProfile);

            DescribeCaptchaResultRequest req = new DescribeCaptchaResultRequest();
            req.setRandstr(rand);
            req.setTicket(ticket);
            req.setCaptchaType(captchaType);
            req.setUserIp(userIp);
            req.setCaptchaAppId(captchaAppId);
            req.setAppSecretKey(appSecretKey);

            DescribeCaptchaResultResponse resp = client.DescribeCaptchaResult(req);

            return DescribeCaptchaResultResponse.toJsonString(resp);
        } catch (TencentCloudSDKException e) {
            return e.toString();
        }
    }
}